using HCore.Tests.Runtime.ShootingEditor2D.Scripts.Command;
using HCore.Tests.Runtime.ShootingEditor2D.Scripts.Support;
using UnityEngine;

namespace HCore.Tests.Runtime.ShootingEditor2D.Scripts.ViewController.GamePlay
{
    /// <summary>
    ///     枪械拾取物品类，用于处理玩家拾取枪械的逻辑
    /// </summary>
    public class GunPickItem : HCoreCommandMonoBehaviour
    {
        [SerializeField] public string GunName;
        [SerializeField] public int BulletCountInGun;
        [SerializeField] public int BulletCountOutGun;

        /// <summary>
        ///     当触发器碰撞发生时调用，检测是否与玩家碰撞并发送拾取枪械命令
        /// </summary>
        /// <param name="other">与当前对象发生碰撞的碰撞器对象</param>
        private void OnTriggerEnter2D(Collider2D other)
        {
            // 检查碰撞对象是否为玩家标签
            if (other.CompareTag("Player"))
            {
                // 发送拾取枪械命令，包含枪械名称和子弹数量信息
                SendCommand(new PickGunCommand(GunName, BulletCountInGun, BulletCountOutGun));
                // 销毁当前游戏对象
                Destroy(gameObject);
            }
        }
    }
}